home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / STRNCMP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  784 b   |  34 lines

  1. /* strncmp.c From TC Bible page 289  Use strncmp to compare a specified number
  2.  of characters of two strings to one another.  The comparison is case
  3.  sensitive.*/
  4.  
  5.  
  6. #include <stdio.h>
  7. #include <string.h>
  8. main()
  9. {
  10.     int len, result;
  11.     char str1[80], str2[80];
  12.     printf("Enter a string: ");
  13.     gets(str1);
  14.     printf("Enter a string to compare with first: ");
  15.     gets(str2);
  16.     printf("How many characters to compare: ");
  17.     scanf(" %d", &len);
  18.     printf("Based on case sensitive comparison of the first %d characters\n",
  19.      len);
  20.     result = strncmp(str1, str2, len);
  21.     if (result == 0)
  22.     {
  23.         printf("\"%s\" == \"%s\"\n", str1, str2);
  24.     }
  25.     if (result < 0)
  26.     {
  27.         printf("\"%s\" < \"%s\"\n", str1, str2);
  28.     }
  29.     if (result > 0)
  30.     {
  31.         printf("\"%s\" > \"%s\"\n", str1, str2);
  32.     }
  33. }
  34.